<?php 
	
    header('HTTP/1.1 200 OK');
	
    $headers="";

    $owner_email = iconv('UTF-8', 'windows-1251',$_POST["owner_email"]); 
    if ($_POST["email"] != 'E-mail:') {
      $headers = 'From:' . iconv('UTF-8', 'windows-1251',$_POST["email"]). "\r\n";
    } 
    $headers .= 'Content-type: text/plain; \n\t charset="windows-1251"' . "\r\n";
    $subject = 'A message from your site visitor ' . iconv('UTF-8', 'windows-1251',$_POST["name"]); 
    $messageBody = ""; 
     
    $messageBody .= '<p>Visitor: ' . iconv('UTF-8', 'windows-1251',$_POST["name"]) . '</p>' . "\n"; 
    $messageBody .= '<br>' . "\n"; 
    $messageBody .= '<p>Email Address: ' . iconv('UTF-8', 'windows-1251',$_POST['email']) . '</p>' . "\n"; 
    $messageBody .= '<br>' . "\n"; 
    $messageBody .= '<p>Phone Number: ' . iconv('UTF-8', 'windows-1251',$_POST['phone']) . '</p>' . "\n"; 
    $messageBody .= '<br>' . "\n"; 
    $messageBody .= '<p>Message: ' . iconv('UTF-8', 'windows-1251',$_POST['message']) . '</p>' . "\n"; 
     
    if($_POST["stripHTML"] == 'true'){ 
        $messageBody = strip_tags($messageBody); 
    } 

    echo "head = ".$headers;
    echo "sub = ".$subject;
    echo "body = ".$messageBody;

    try{ 
        if(!mail($owner_email, $subject, $messageBody, $headers)){ 
            throw new Exception('mail failed'); 
        }else{ 
            echo 'mail sent'; 
        } 
    }catch(Exception $e){ 
        echo $e->getMessage() ."\n"; 
    } 
?>